package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Date;
import java.util.HashMap;

/**
 * 攻略细节
 */
@Getter@Setter@ToString
public class StrategyDetail extends BaseDomain {
    public static final Integer STATE_RELEASE = 1;//发布
    public static final Integer STATE_COMMON = 0;//草稿
    public static final Integer STATE_DISABLE = -1;//禁用
    private String title;//标题

    private Date createTime;//创建时间

    private Date releaseTime;//发布时间

    private Integer sequence;//序号

    private StrategyCatalog catalog;//分类目录

    private String coverUrl;//封面

    private Integer state;//状态

    private StrategyContent content;//攻略内容

    public String getStateName(){
        String stateName = "草稿";
        if (STATE_RELEASE.equals(state)) {
            stateName = "发布";
        }else if (STATE_DISABLE.equals(state)) {
            stateName = "禁用";
        }
        return stateName;
    }

    public String getJson(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        map.put("sequence",sequence);
        map.put("state",state);
        if (catalog != null) {
            if (catalog.getStrategy() != null) {
                map.put("strategyId",catalog.getStrategy().getId());
            }
            map.put("catalogId",catalog.getId());
        }
        if (content != null) {
            map.put("content",content.getContent());
        }
        return JSONUtil.toJSONString(map);
    }

}